package com.hp.ongoing;

import java.awt.BorderLayout;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hp.ongoing.entity.AutenticacaoUsuario;
import com.hp.ongoing.entity.ContratoVO;
import com.hp.ongoing.entity.QuantidadePeriodo;
import com.hp.ongoing.persistence.constants.QueryConstants;
import com.hp.ongoing.persistence.exception.DataBaseAcessException;
import com.hp.ongoing.persistence.factory.ConnectionFactory;
import com.hp.ongoing.persistence.repository.JdbcRepository;

public class MockTest {

	final static Logger logger = LoggerFactory.getLogger(MockTest.class);

	public static void main(String[] args) {


		AutenticacaoUsuario user = new AutenticacaoUsuario();
		user.setSenha("luis2007");
		user.setUsuario("e_t3lcele");
		user.setBase("DTHPPRD");

		try {
			System.out.println(ConnectionFactory.getInstance().getConnection(
					user));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		JdbcRepository repository = JdbcRepository.getInstance(user);
		Map<String,String> params = new HashMap<String, String>();
//		
////*****TESTE SELECT****************		
		List contratos = new ArrayList();
//		params.put(":rownum", "4");
//		params.put(":idDiaVcto", "1");
//		try {
//			contratos = repository.findResultsByQuery(QueryConstantsEnum.RECUPERA_CONTRATOS,QuantidadePeriodo.class, params);
//			Iterator it = contratos.iterator();
//			ContratoVO contrato = new ContratoVO();
//			while (it.hasNext()){
//				contrato= (ContratoVO) it.next();
//				System.out.println(contrato.getNumContrato());
//			}
//		} catch (DataBaseAcessException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		
		
		List contratos2 = new ArrayList();
		params.put(":contratos", "12197, 12200, 12219, 512542");
		try {
			contratos = repository.recuperarContratos(QueryConstants.RECUPERAR_CONTRATOS, params);
			Iterator it = contratos.iterator();
			ContratoVO contrato = new ContratoVO();
			while (it.hasNext()){
				contrato= (ContratoVO) it.next();
				System.out.println(contrato.getNumContrato()+"|"+contrato.getIdDiaVcto()+"|"+contrato.getIdMacroSegmento()+"|"+contrato.getIdTipoCobranca());
			}
		} catch (DataBaseAcessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

//
////*****TESTE INSERT****************
//		Map<String,String> params = new HashMap<String, String>();
//		params.put(":dsAtividade", "TESTE APP");
//		params.put(":identificador", "AFH03");
//		try {
//			repository.insertPrevisao(QueryConstantsEnum.INSERIR_PREVISAO, params);
//		} catch (DataBaseAcessException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//
		
		
		

//		    JFrame frame = new JFrame();
//		    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//
//		    Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" },
//		        { "Row2-Column1", "Row2-Column2", "Row2-Column3" } };
//		    Object columnNames[] = { "Column One", "Column Two", "Column Three" };
//		    JTable table = new JTable(rowData, columnNames);
//
//		    JScrollPane scrollPane = new JScrollPane(table);
//		    frame.add(scrollPane, BorderLayout.CENTER);
//		    frame.setSize(300, 150);
//		    frame.setVisible(true);

		
		
	}

}
